const Timestamp = new Date().getTime();

module.exports = {
  publicPath: "/",
  outputDir: "dist",
  filenameHashing: true,
  lintOnSave: true,
  productionSourceMap: false,
  devServer: {
    host: "0.0.0.0",
    disableHostCheck: true,
    open: true,
    port: 82,
    proxy: {
      "/api": {
        // '/api': {
        // target: "http://192.168.111.127:8080",
        // target: 'http://192.168.111.221:8080',
        // target: 'https://marketing-api.xiangsaopay.com',
        // target: 'http://xiangsaodev.5gzvip.91tunnel.com',
        // target: 'http://172.16.20.122:6002',
        // target: 'https://marketing-api.xiangsaopay.com/',
        // target: "http://192.168.111.135:8080",
        // target: 'http://cloud.fuhuiba.ltd/api',
        // target: 'https://cloudtest.fuhuiba.ltd/api',
        target: "https://merchh5test.fuhuiba.ltd/api",
        // target: 'https://agenthh5test.xiangsaopay.com/api',
        // target: process.env.VUE_APP_BASE_API,
        ws: true,
        secure: false,
        changeOrigin: true,
        pathRewrite: {
          "^/api": "/",
        },
      },
    },
  },
  // 打包添加时间戳，防止缓存
  configureWebpack: {
    output: {
      // 输出重构  打包编译后的 文件名称  【模块名称.版本号.时间戳】
      filename: `static/js/[name].${Timestamp}.js`,
      chunkFilename: `static/js/[name].${Timestamp}.js`,
    },
  },
  chainWebpack: (config) => {
    // if (process.env.NODE_ENV === "production") {
    config.optimization.minimize(true);
    // 移除prefetch插件，避免加载多余的资源
    config.plugins.delete("prefetch");
    // 移除 preload 插件，避免加载多余的资源
    config.plugins.delete("preload");

    config.optimization.splitChunks({
      chunks: "all",
      minSize: 50000, // 字节 引入的文件大于50kb才进行分割
      maxSize: 100000, // 100kb，尝试将大于100kb的文件拆分成n个100kb的文件
      minChunks: 1, // 模块至少使用次数
      maxAsyncRequests: 5, // 同时加载的模块数量最多是5个，只分割出同时引入的前5个文件
      maxInitialRequests: 3, // 首页加载的时候引入的文件最多3个
      cacheGroups: {
        libs: {
          name: "chunk-libs",
          test: /[\\/]node_modules[\\/]/,
          priority: 0,
          minSize: 50000,
          chunks: "all", // only package third parties that are initially dependent
          // maxSize: 32000
        },
        common: {
          chunks: "all",
          test: /[\\/]src[\\/]js[\\/]/,
          name: "common",
          minChunks: 2,
          maxInitialRequests: 5,
          minSize: 50000,
          priority: 3,
          // maxSize: 32000
        },
        styles: {
          name: "styles",
          test: /\.(sa|sc|le|c)ss$/,
          chunks: "all",
          enforce: true,
          minSize: 50000,
          reuseExistingChunk: true,
          // maxSize: 32000
        },
      },
    });
    // }
  },
};
